/**
 * There are code generation
 */
package com.neusoft.lohas.modules.ivm.service.product;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.lohas.common.persistence.Page;
import com.neusoft.lohas.common.service.BaseService;
import com.neusoft.lohas.modules.ivm.dao.product.ProductMarketDetailDao;
import com.neusoft.lohas.modules.ivm.entity.product.ProductMarketDetail;

/**
 * 商品市场价记录Service
 * @author Jackie.Liu
 * @version 2015-09-09
 */
@Component
@Transactional(readOnly = true)
public class ProductMarketDetailService extends BaseService {

	@Autowired
	private ProductMarketDetailDao productMarketDetailDao;
	
	public ProductMarketDetail get(String id) {
		return productMarketDetailDao.get(id);
	}
	
	public Page<ProductMarketDetail> find(Page<ProductMarketDetail> page, ProductMarketDetail productMarketDetail) {
		DetachedCriteria dc = productMarketDetailDao.createDetachedCriteria();
		dc.add(Restrictions.eq(ProductMarketDetail.FIELD_DEL_FLAG, ProductMarketDetail.DEL_FLAG_NORMAL));
		dc.add(Restrictions.eq("product.id", productMarketDetail.getProduct().getId()));
		dc.add(Restrictions.eq("type", productMarketDetail.getType()));
		dc.addOrder(Order.desc("createDate"));
		return productMarketDetailDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(ProductMarketDetail productMarketDetail) {
		productMarketDetailDao.save(productMarketDetail);
	}
	
	@Transactional(readOnly = false)
	public void save(List<ProductMarketDetail> list) {
		productMarketDetailDao.save(list);
	}
	
	@Transactional(readOnly = false)
	public void delete(String id) {
		productMarketDetailDao.deleteById(id);
	}

}
